<template>
  <div>
    <el-drawer
      :append-to-body="true"
      :before-close="handleClose"
      :direction="direction"
      size="40%"
      title="我是子组件"
      :visible.sync="drawer"
    >
      <div>
        <el-form class="demo-form-inline" :inline="true" :model="formInline">
          <el-form-item label="审批人">
            <el-input v-model="formInline.user" placeholder="审批人"></el-input>
          </el-form-item>
          <el-form-item label="活动区域">
            <el-select v-model="formInline.region" placeholder="活动区域">
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">确认</el-button>
            <el-button type="primary" @click="onClose">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-drawer>
  </div>
</template>
<script>
export default {
  name: 'DrawerPage',
  props: {
    innwer: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      direction: 'rtl',
      drawer: false,
      formInline: {
        user: '',
        region: ''
      }
    }
  },
  watch: {
    innwer(val) {
      console.log('val', val)
      this.drawer = val
    }
  },
  methods: {
    onSubmit() {
      console.log('submit!')
      this.formInline = {
        user: '',
        region: ''
      }
      this.$emit('update:innwer', false)
    },
    onClose() {
      this.formInline = {
        user: '',
        region: ''
      }
      console.log('submit!')
      this.$emit('update:innwer', false)
    },
    handleClose(done) {
      this.$confirm('还有未保存的工作哦确定关闭吗？')
        .then(_ => {
          this.$emit('update:innwer', false) // 触发自定义事件通知父组件修改 innwer 的值
          done()
        })
        .catch(_ => {})
    }
  }
}
</script>
